$(function() {

	//轮播效果

	jQuery(".sq-l").slide({ titCell:".num li", mainCell:".pic",effect:"fold", autoPlay:true,



		startFun:function(i){



			jQuery(".sq-l .txt li").eq(i).animate({"bottom":0}).siblings().animate({"bottom":-49+'px'});



		}});


	jQuery(".my-photo").slide({mainCell:".bd ul",autoPlay:true});



	jQuery(".watch-item").slide({titCell:".hd ul",mainCell:".bd .ulWrap",autoPage:true,effect:"leftLoop",autoPlay:true,vis:5});



	//banner图右侧效果



	$(".sq-standard .sq-r li").mouseover(function() {



		$(this).addClass('on').siblings().removeClass('on');



	});



	//我的好友



	$('.myfocus a').click(function(event) {



		var myIndex=$(this).index();



		$(this).addClass('on').siblings().removeClass('on');



		$('.friend-item').eq(myIndex).addClass('current').siblings().removeClass('current');



	});



	//我的好友tab



	$(".fr-nav a").click(function(event) {



		var frIndex=$(this).index();



		$(this).addClass('on').siblings().removeClass('on');



		$('.sq-fr-pane').eq(frIndex).addClass('current').siblings().removeClass('current');



	});

	

	

	// 关注

	$(".guanzhu").click(function(){

		var mid = $(this).attr("mid");

		if(mid){

			$.ajax({ 

				url:'clickfavorite.php', 

				type:'post',

				dataType:'html',

				data:'action=add&tid=' + mid + '&date='+new Date(),

				error: function(){

					alert('Error loading document'); 

				},success: function(msg){
					setTimeout(parent.location.reload(),1000);
					alert(msg);

				} 

			});

		}else{

			alert('参数错误');	

		}

	});

	

	

	

	



	//我的订单(取消/选择)







	$('.J_AllSelector').change(function(){







		if($(this)[0].checked){







			$('.J_Selector').each(function(index, el) {







				$(this)[0].checked = true;







			});







		}else{







			$('.J_Selector').each(function(index, el) {







				$(this)[0].checked = false;







			});







		}







	});







	$('.J_Selector').change(function(){







		if(!$(this)[0].checked){







			if($('.J_AllSelector')[0].checked){







				$('.J_AllSelector')[0].checked = false;







			}







		}







	});







	$('.operates .cancel').click(function(){







		$('.J_Selector').each(function(index, el) {







			$(this)[0].checked = false;







		});







		$('.J_AllSelector')[0].checked = false;







	});







	//删除选中的商品







	$('.operates .delete').click(function(){







		$('.J_Selector').each(function(index, el) {







			if($(this)[0].checked){







				//$(this).parents('tbody').remove();







			}







		});







	});







	//删除草稿







	$('.operates .delete').click(function(){







		$('.J_Selector').each(function(index, el) {







			if($(this)[0].checked){







				$(this).parents('.draft-item').remove();







			}







		});







	});







	//删除通知







	$('.operates .delete').click(function(){







		$('.J_Selector').each(function(index, el) {







			if($(this)[0].checked){







				$(this).parents('.annouce-item').remove();







			}







		});







	});















	//删除退款通知







	$('.operates .delete').click(function(){







		$('.J_Selector').each(function(index, el) {







			if($(this)[0].checked){







				$(this).parents('.refund-item').remove();







			}







		});







	});















	//编辑器代码







    $(".act-reply").click(function() {







        event.stopPropagation();







        $('.comments-box').hide();







        $('.comment-box-wrap').hide();







        $(this).parents('.comments-content').siblings('.comment-box-wrap').show().find('.textarea').select();







    });





    $(".comments-box").on('click', function(event) {







    	$('.comments-box').show();







        $('.comment-box-wrap').hide();







        $(this).hide();







        $(this).siblings('.comment-box-wrap').show().find('.textarea').focus();







    });







    $(".comment-box-wrap").on('click', function(event) {







    	$('.comment-box-wrap').not(this).hide();







    	$(this).siblings('.comments-box').hide();







    });







	/*$('body').on('click', function (e){







		$('.comments-box').show();







		$('.comment-box-wrap').hide();







	});







	$('.comment-box-wrap').on('click', function(e){







		e.stopPropagation();







	});*/



	//显示X

	$(".mod-comments .comments-list .comments-op").hover(function(){

		$(this).find('.act-delete').removeClass('none');

	},function(){

		$(this).find('.act-delete').addClass('none');

	});



    //删除评论

    $(".mod-comments .comments-op .act-delete").click(function(e) {

        e.preventDefault();

        var _this=$(this);

        var url=$(this).attr('href');

        $.ajax({

            url: url,

            type: 'post',

            dataType: 'json',

        })

        .done(function(data) {

            data=eval(data);

            if (data.status==0) {

                _this.closest('.comments-item').remove();



                layer.msg('删除成功',{

                    time:800

                })

            };

        })

        .fail(function(data) {

            layer.msg('删除失败',{

                icon:2,

                time:2000

            });

        });

        

        // $(this).closest('.comments-item').remove();

    });



	//上传的图片的展现情况

	var $imgBox = $('.img-box');

	$imgBox.each(function(){

		var imgBoxWidth = $(this).width();

		var $img = $(this).find('img');

		var count = $img.length;

		if(count == 0){

			$(this).parents('.f-ct').hide();

		}else if(count == 1){

			var imgWidth;

			var imgHeight;

			$img.each(function() {

				imgWidth = this.width;

				imgHeight = this.height;

				if(imgHeight<384){

					$img.width(imgWidth);

					$img.height(imgHeight);

				}else{

					$img.width(imgBoxWidth);

				}

			});

			$img.fadeIn(200);

		}else if(count == 2){

			$(this).children('.img').addClass('img-two');

			$img.width(imgBoxWidth / 2-4);

			$img.fadeIn(200);

		}else if(count > 2){

			$(this).children('.img').addClass('img-three');

			$img.width(imgBoxWidth / 3-4);

			$img.fadeIn(200);

		}

	})





    // 发布的编辑器

    $('.sq-editor-cont').each(function(index, el) {

    	var _this=$(this);

        var btnImgUpload = $(this).find('.btn-img-upload');

        var sqEditorPics = $(this).find('.sq-editor-pics');

        var btnPost=$(this).find('.btn-post');

        var btnLinkAppend=$(this).find('.btn-link-append');

        var strHtml=$(this).find('.textarea');

        var strHtmlHidden=$(this).find('.textarea-hidden');



        // 删除图片

        sqEditorPics.on('click', 'li .btn-rm', function(event) {

        	event.preventDefault();



        	$(this).closest('li').remove();



        	if (sqEditorPics.find('li').length==0) {

        		sqEditorPics.hide();

        	};

        });

        // 图片上传

        btnImgUpload.on('click', function(event) {

            $(this).fileupload({

                url: '/server/index.php',

                dataType: 'json',

                add: function(e, data) {

                    data.submit();

                    layer.open({

                        content: "正在上传中,请耐心等待~",

                        closeBtn: false,

                        shadeClose: false

                    });

                },

                done: function(e, data) {

                    if (data.result.error == 0) {

                        layer.msg('上传成功',{

                        	icon:1,

                            time: 2000

                        });

                        var str='<li><img src="server/'+data.result.url+'" /><i class="btn-rm">x</i><input name="images[]" type="hidden" value="server/'+data.result.url+'"/></li>'

                        sqEditorPics.show().find('ul').append(str);

                    } else {

                        layer.msg(data.result.message,{

                        	icon:2,

                            time: 2000

                        });

                    }

                },

                progressall: function(e, data) {

                    console.log(data);

                }

            });

        });

		// 提交表单

		btnPost.on('click', function(event) {

			event.preventDefault();

			strHtmlHidden.val(strHtml.html());

			$(this).closest('form').submit();

		});

		// 添加链接

		btnLinkAppend.on('click', function(event) {

			event.preventDefault();

			_this.closest('.mod-commnets-poster').addClass('lock');

			layer.open({

			    type: 1,

			    shade: false,

			    title:'添加超链接',

			    btn: ['保存','取消'],

			    area:'400px',

			    content: '<ul class="sq-editor-link"> <li><label>链接文字：</label><input class="text" type="text" placeholder="请输入链接文字" /></li> <li><label>链接地址：</label><input class="url" type="text" placeholder="请输入链接地址" /></li> </ul>',

			    yes: function(index, layero){ 

			        var text=layero.find('.text').val();

			        var url=layero.find('.url').val();

			        strHtml.append('<a target="_blank" href="'+url+'">'+text+'</a>');

			        layer.close(index);

			        

			    },

			    end:function(index,layero){

			    	

			    }



			});

		});

    });



    // 发布页面，点赞工具条

    $('.f-single').each(function(index, el) {

    		var _this=$(this);

    		var comment=$(this).find('.f-detail-comment');

    		var praise=$(this).find('.f-detail-praise');

    		var collect=$(this).find('.f-detail-collect');

    		var cdelete=$(this).find('.f-detail-delete');

            var userlike=$(this).find('.f-like');

            var userlist=userlike.find('.user-list');

            if (userlist.find('a').length==0) {

                userlike.hide();

            };

            // 回复

    		comment.on('click', function(event) {

    			event.preventDefault();

    			_this.find('.comments-box').click();

    		});

            // 点赞

    		praise.on('click', function(event) {

    			event.preventDefault();

                var url=$(this).attr('href');

                $.ajax({

                    url: url,

                    type: 'POST',

                    dataType: 'JSON',

                })

                .done(function(data) {

                    data=eval(data);

                    if (data.status==0) {

                        userlist.append('<a target="_blank" href="'+data.home+'" title="'+data.name+'"><img src="'+data.head+'" /></a>')

                        praise.find('.num').text(parseInt(praise.find('.num').text())+1);

                        userlike.show();

                        layer.msg('+1',{

                            shift :0,

                            time:800

                        });

                    }else if(data.status==1){

                        layer.msg('你已经赞过了~',{

                            icon:1,

                            time: 800

                        });

                    }else{

                         layer.msg('点赞失败~',{

                            icon:2,

                            time: 800

                        });

                    }

                })

                .fail(function() {

                    layer.msg('游客请登录后点赞~',{

                        icon:2,

                        time: 800

                    });

                });

    		});

            // 收藏

            collect.on('click', function(event) {

                event.preventDefault();

                var url=$(this).attr('href');

                $.ajax({

                    url: url,

                    type: 'POST',

                    dataType: 'JSON',

                })

                .done(function(data) {

                    if (data.status==0) {

                        layer.msg('已收藏',{

                            shift :0,

                            time:800

                        });

                    }

                    else{

                        layer.msg('收藏失败~',{

                            icon:2,

                            time: 800

                        });

                    }

                    

                })

                .fail(function() {

                    layer.msg('收藏失败~',{

                        icon:2,

                        time: 800

                    });

                });

            });

            // 删除

            cdelete.on('click', function(event) {

                event.preventDefault();

                var url=$(this).attr('href');

                $.ajax({

                    url: url,

                    type: 'POST',

                    dataType: 'JSON',

                })

                .done(function(data) {

                     if (data.status==0) {

                        _this.remove();

                        layer.msg('已删除',{

                            shift :0,

                            time:800

                        });

                     }

                     else{

                        layer.msg('删除失败~',{

                            icon:2,

                            time: 2000

                        });

                     }

                        

                })

                .fail(function() {

                    layer.msg('删除失败~',{

                        icon:2,

                        time: 2000

                    });

                });

            });



    });

    //活动详情页面 点击加入感兴趣

	$('.mdd-2 .good').click(function(event) {



		  event.preventDefault();







	      var url=$(this).parent().attr('href');







		   $.ajax({







			url: url,







			type: 'POST',







			dataType: 'html',







          })







		   .done(function(data) {







			   







			     layer.msg(data,{







                        icon:1,







                        time: 800







                 });







            })







			.fail(function() {







				layer.msg('失败~',{







					icon:2,







					time: 800







				});







			});







	   });















	//头像设置







	$(".new-pic-l .imageBox").hover(function(){







		$("body").css("overflow","hidden");







	},function(){







		$("body").css("overflow","auto");







	})

	//填写订单（层级关系）

	$('.order-top-tips li:first').css('margin','0');

	var num = $('.order-top-tips li').length;

	$('.order-top-tips li').each(function(){


		$(this).css({'zIndex':1+num});


		num--;




	})


	//订单付款方式


	$('.order-price').find('.price').eq(0).show();

	var price_v1=$('.order-price').find('.price').eq(0).find('em').html();

	var price_v2=$('.order-price').find('.price').eq(1).find('em').html();

	var price_total = $('.order-post .order-price-total span em');

	$(".order-pirce-op a").click(function(){

		var opIndex=$(this).index();

		$(this).addClass('on').siblings().removeClass('on');

		$(this).parents('.order-price').find('.price').eq(opIndex).show().addClass('on').siblings('.price').hide().removeClass('on');

		var order_isfull=$("input[name='order_isfull']");

		var price_1=$(this).parents('.order-price').find('.price').eq(0);

		var order_p=$(".order-info").length;


		if (!price_1.is(":hidden")) {

			order_isfull.val(1);

		}else{

			order_isfull.val(0);

		}

		if (!price_1.is(":hidden")) {

			price_total.html(Number(Number(price_v1).toFixed(2)*order_p).toFixed(2));

		}else{

			price_total.html(Number(Number(price_v2).toFixed(2)*order_p).toFixed(2));

		}

	});


	//添加游客信息

	var $add_person=$('.add-p a');
	$add_person.on('click',function(){

		var _html = [];

		_html.push('');

		_html.push('<div class="order-info user-added">');

		_html.push('<div class="orderer-info">');

		_html.push('<span>客户姓名:</span>');

		_html.push('<input type="text" class="input_wby1 o_right w134" name="order_realname[]" placeholder="请输入客户姓名"/>');

		_html.push('</div>');

		_html.push('<div class="orderer-info">');

		_html.push('<span>联系电话:</span>');

		_html.push('<input type="text" class="input_wby1 o_right w154" name="order_phone[]" placeholder="请输入手机号码"/>');

		_html.push('</div>');

		_html.push('<div class="orderer-info">');

		_html.push('<span>身份证号/护照号:</span>');

		_html.push('<input type="text" class="input_wby1 o_right w288" name="order_idcard[]" placeholder="请输入身份证号码"/>');

		_html.push('</div>');

		_html.push('<div class="orderer-info">');

		_html.push('<span>上车地点:</span>');

		_html.push('<input type="text" id="identity"  class="input_wby1 o_right w288" value="" name="order_shangche[]" placeholder="请输入上车地"/>');

		_html.push('</div>');

		_html.push('<div class="orderer-info nr">');

		_html.push('<span>备注:</span>');

		_html.push('<input type="text" class="input_wby1 w1045"  name="order_text[]" placeholder="请输入要备注的信息！注意性别"/>');

		_html.push('</div>');

		_html.push('<div class="delete_p">');

		_html.push('<a href="javascript:;">删除</a>');

		_html.push('</div>');

		_html.push('</div>');

		var $item=$(_html.join(''));

		$item.appendTo('.order-info-wrapper');

		$item.find('.delete_p a').on('click',function(event) {

			$item.remove();
			var order_p=$(".order-info").length;
			var new_value=Number($(".order-item .order-detail .order-price span.on").find('em').html()).toFixed(2);
			
			price_total.html(Number(new_value*order_p).toFixed(2));

		});	

		var order_p=$(".order-info").length;

		var new_value=Number($(".order-item .order-detail .order-price span.on").find('em').html()).toFixed(2);

		price_total.html(Number(new_value*order_p).toFixed(2));

	});

	// 验证信息是否完善
	$('#order-post').on('click', function () {

		var flag = false;
		$('.orderer-info .o_right').each(function(index, el) {
			var values = $(this).val();
			if (values) {
				flag = true;
			}else{
				flag = false;
				return false;
			}
		});
		if (!flag) {
			layer.alert('信息未完善，请您先完善信息!', { icon: 6})
		}
		return flag;

	})


});


//活动内容选择


$(function (){



	function DealDraft(html){



		var $element = $(html);



		$element.find('.op-c').on('click', function(e){



			//请求后台获得主要内容



			var _id = $(this).attr('data-id');



			var _startpro = $(this).attr('data-startpro');



			var _startcity = $(this).attr('data-startcity');



			var _endpro = $(this).attr('data-endpro');



			var _endcity = $(this).attr('data-endcity');



			var _url = 'tpl_inner.php'; // 请求后台选用的地址



			$.ajax({



				url:_url,



				data: {newsid: _id},



				type: 'get',



				dataType: 'html',



				success: function (data){



					$('#editorInner').html(data);



					layer.closeAll();



					 editor = KindEditor.create('textarea[name=active_line]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_charge_details]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_xingcheng]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_zhuangbei]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_baoming]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_ditu]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});



					 editor = KindEditor.create('textarea[name=active_koubei]', {width:'100%',filterMode: false,afterBlur: function(){this.sync();}});







					 $(".departure_select").citySelect({prov:_startpro, city:_startcity});



    				 $(".destination_select").citySelect({prov:_endpro, city:_endcity});



    				 	var editor = KindEditor.editor({



							allowFileManager : false



						});







						$('.upload-img2').click(function() {
							editor.loadPlugin('image', function() {
								editor.plugin.imageDialog({
									imageUrl : $('#active_pic').val(),
									clickFn : function(url, title, width, height, border, align) {
										$('#active_banner').val(url);
										editor.hideDialog();
									}
								});
							});
						})


						$('#upload-images').click(function() {
			editor.loadPlugin('multiimage', function() {
				editor.plugin.multiImageDialog({
					clickFn : function(urlList) {
						$.each(urlList, function(i, data) {
						
			           var li ='<li><input type="text" class="editor-input w790" style="width:310px;margin-left:135px;" name="active_pic[]" value="'+data.url+'" id="active_pic"><a class="shanchu" style="color: red;margin-left: 5px;" href="javascript:;">X</a><input type="hidden" name="active_sollimg[]" class="active_sollimg" value="'+data.thumb+'" /></li>';
			            $("#photo-one").prepend(li);
						
						});
							$(".shanchu").on('click',function(){
								var div = $(this).parent("li");
								var URL = $(this).siblings('.editor-input').val();
									URL += ',';
									URL += $(this).siblings('.active_sollimg').val();
								$.ajax({
									type:"post",
									url:"ajax.php?tu=pian",
									data:{URL:URL},
									dataType:"json",
									success:function(data){
										if(data == 33){
											div.remove();
											alert("文件已经被删除")
										}
										if(data == 22){
											div.remove();
											alert("文件删除失败")
										}else{
											div.remove();
										}
									}
								});
							})
						editor.hideDialog();
					}
				});
			});
		});
    				 



					 writeHd();			



				},







				error: function(){







					alert('加载失败')







				}







			})







		});















		$element.find('.op-d').on('click', function (e){







			var _id = $(this).attr('data-id');







			var _url = 'forum_activeaddsave.php?action=delactive'; // 请求后台删除的地址







			var $parent = $(this).parent();







			$.ajax({







				url: _url,







				data: {newsid: _id},







				type: 'post',







				dataType: 'json',







				success: function (data){







					if(data.result){







					layer.msg('删除成功')







					$parent.parent().remove();	







					}







				},







				error: function(){







					layer.msg('删除失败')







				}







			});







		});















	}















	//查看草稿箱







	$(document).on('click', '.draft_btn', function(event) {







		event.preventDefault();







		var url=$(this).attr('href');







		$.ajax({







			url: url,







			type: 'get',







			dataType: 'html'







		})







			.done(function(data) {







				// 返回草稿箱内容的html代码







				layer.open({







					type: 1,







					title:false,







					shadeClose: true,







					shift :3,







					area:'1050px',







					content: data,







					success: function (_l){







						DealDraft(_l);







					}







				});







			})







			.fail(function() {







				layer.msg('加载失败');







			})















	})







	function writeHd(){







		$('.hd-mark > ul > li > a').off('click');







		$('.hd-mark > ul > li > a').on('click', function (){







			var $parent = $(this).parents('li');







			var _text = $(this).text();







			var $tempDom = $parent.parents('.hd-mark').prev('.basic-hide');







			if(!$parent.hasClass('selected')){







				var $dom = $(this).parents('.hd-mark').prev('.basic-hide');







				var $inputBox = $(this).parents('.hd-mark').prev('.basic-hide').children('input[type="text"]');







				var _item = '<span>' + _text + '</span>';







				$inputBox.before(_item);







				AddRemoveCalss($dom)







			}else{







				var $dom = $(this).parents('.hd-mark').prev('.basic-hide');







				RemoveItem($dom, _text);







			}







			CheckSelect($tempDom);







		});







		$('.basic-hide').on('click', function (){







			$(this).children('input[type="text"]').focus();







			$(this).next('.hd-mark').show();







		});











		function CheckSelect(dom){







			var $dom = $(dom);







			var $selectedItems = $dom.children('span');







			var $item = $dom.next('.hd-mark').find('ul > li > a');







			var _len = $item.length;







			var sitemInfo = [];















			for(var i = 0; i < _len; i++){







				$($item[i]).parents('li').removeClass('selected');







				var _text = $($item[i]).text();







				var _l = $selectedItems.length;







				for(var j = 0; j < _l; j++){







					var text = $($selectedItems[j]).text();







					if(_text == text ){







						$($item[i]).parents('li').addClass('selected');







					}







				}







			}







			var _l = $selectedItems.length;







			for(var i = 0; i < _l; i++){







				var text = $($selectedItems[i]).text();







				sitemInfo.push(text);







			}







			$dom.find('input[type="hidden"]').val(sitemInfo.join(','));







		};







		function RemoveItem(dom, text){







			var $dom = $(dom)







			var $selectedItems = $dom.children('span');







			$selectedItems.each(function(index, el) {







				var _text = $(this).text();







				if(_text == text){







					$(this).remove();







				}







			});







		}







		function AddRemoveCalss(dom){







			var $dom = $(dom);







			var $items = $dom.find('span');







		}











		//发布页面编辑器选择







		$('.editor-tab a').click(function(event) {







			var editorIndex=$(this).index();







			$(this).addClass('on').siblings().removeClass('on');







			$('.editor-textBox-bd>div').eq(editorIndex).show().siblings().hide();







		});











		//出行方式







		$("#id_chartered_0").click(function(event) {







			$("#businfo").show();







			$("#othervehicle").hide();







		});







		$("#id_chartered_1").click(function(event) {







			$("#othervehicle").show();







			$("#businfo").hide();







		});







		if($("#othervehicle input[type=checkbox]").is(':checked')){



			$("#othervehicle").show();



			$("#businfo").hide();



		};







		$(".save-draft").click(function(){



		  $("#savemodel").val(1);



		 document.myform.submit();



		 });



	}







	writeHd();







	//点击菜单展开







	$(".member-nav-bd dl").each(function(index, el) {







		$('.member-nav-bd dt .icon').addClass('on');







		







	});







	$(".member-nav-bd dt .icon").click(function(){







		var icon_choose=$(this);







		if(!icon_choose.hasClass('on')){







			$(this).addClass('on');







			$(this).parents('.member-nav-bd dl').find('.child-nav').slideDown();







		}







		else{







			$(this).removeClass('on');







			$(this).parents('.member-nav-bd dl').find('.child-nav').slideUp();







		}







	})







	//发布活动页面操作















});















